package cn.edu.baiyunu.myapplication.ui.home

import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import cn.edu.baiyunu.myapplication.data.repository.PhotoRepository
import cn.edu.baiyunu.myapplication.data.repository.PreferenceRepository

/**
 * HomeViewModel的工厂类，用于创建带参数的ViewModel实例
 */
class HomeViewModelFactory(
    private val preferenceRepository: PreferenceRepository,
    private val photoRepository: PhotoRepository
) : ViewModelProvider.Factory {
    
    @Suppress("UNCHECKED_CAST")
    override fun <T : ViewModel> create(modelClass: Class<T>): T {
        if (modelClass.isAssignableFrom(HomeViewModel::class.java)) {
            return HomeViewModel(preferenceRepository, photoRepository) as T
        }
        throw IllegalArgumentException("Unknown ViewModel class")
    }
} 